var common = {
  baseUrl: "http://192.168.0.87:3000", //冯兆全
  //日期格式化，默认yyyy-MM-dd hh:mm:ss
  dateFormat: function(time, fmt) {
    if(!time) {
      return "";
    }
    fmt = fmt || "yyyy-MM-dd hh:mm:ss";
    var d = new Date(time);
    var o = {
      "M+": d.getMonth() + 1, //月份   
      "d+": d.getDate(), //日   
      "h+": d.getHours(), //小时   
      "m+": d.getMinutes(), //分   
      "s+": d.getSeconds(), //秒   
      "q+": Math.floor((d.getMonth() + 3) / 3), //季度   
      "S": d.getMilliseconds() //毫秒   
    };
    if(/(y+)/.test(fmt))
      fmt = fmt.replace(RegExp.$1, (d.getFullYear() + "").substr(4 - RegExp.$1.length));
    for(var k in o)
      if(new RegExp("(" + k + ")").test(fmt))
        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
  },
  //获取url参数
  getUrlParams: function(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if(r) {
      return decodeURI(r[2]);
    } else {
      return null;
    }
  },
  //get请求
  get: function(obj) {
    obj.type = "GET";
    this.ajax(obj);
  },
  //post请求
  post: function(obj) {
    obj.type = "POST";
    this.ajax(obj);
  },
  //ajax基础方法
  ajax: function(obj) {
    $.ajax({
      type: obj.type,
      url: this.baseUrl + obj.url,
      data: obj.data,
      headers: {
        "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
      },
      dataType: "json",
      success: function(data) {
        if(typeof data == "string") {
          data = JSON.parse(data)
        }
        if(data.code == 500) {
          alert(data.msg)
        }
        obj.callback(data)
      }
    });
  }

}